<template>
  <div id="potion">
    <category-scroll class="content" :pull-up-load="true" ref="scroll">
      <div class="potion-list">
        <ul>
          <li
            v-for="(item, index) in potionList"
            :key="index"
            :class="{ active: currentIndex === index }"
            @click="positionToggle(index)"
          >
            <span>{{ item.title }}</span>
          </li>
        </ul>
      </div>
    </category-scroll>
  </div>
</template>

<script>
import CategoryScroll from '../../../components/common/Scroll/Scroll'

export default {
  props: {
    potionList: Array
  },
  data() {
    return {
      currentIndex: 0 // 当前选项索引
    }
  },
  components: {
    CategoryScroll
  },
  mounted() {},
  methods: {
    // 切换到对应的选项
    positionToggle(index) {
      this.currentIndex = index
      this.$emit('clickcategory', index)
    }
  },
  watch: {
    potionList() {
      this.$nextTick(() => {
        this.$refs.scroll.refresh()
      })
    }
  }
}
</script>

<style lang="less" scoped>
#potion {
  li {
    width: 100px;
    height: 45px;
    line-height: 45px;
    background-color: #f6f6f6;
    text-align: center;
    font-size: 14px;
  }
  .active {
    border-left: 3px solid var(--color-a);
    color: var(--color-a);
    background-color: #fff;
  }
}

.content {
  height: 100%;
}
</style>
